package com.eight.lesson3;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;

import com.eight.lesson2.Apple;

public class FunctionQuote {

	public static void main(String[] args) {
		// 构造引用
		BiFunction<Integer, String, Apple> c2 = Apple::new;
		Apple a = c2.apply(122, "red");
		System.out.println(a.getColor()+":"+a.getWeight());
		
		Apple apple1 = new Apple(150, "red");
		Apple apple2 = new Apple(130, "green");
		Apple apple3 = new Apple(110, "yellow");
		
		List<Apple> apples = new ArrayList<Apple>();
		apples.add(apple1);
		apples.add(apple2);
		apples.add(apple3);
		
		// 方法引用来排序
		System.out.println("-------------方法引用排序前-----------------");
		for(Apple apple : apples) {
			System.out.println(apple.getWeight());
		}
		apples.sort(Comparator.comparing(Apple::getWeight));
		System.out.println("-------------方法引用排序后-----------------");
		for(Apple apple : apples) {
			System.out.println(apple.getWeight());
		}
	}

}
